<table width="100%"  border="0" cellpadding="3" cellspacing="1">
  <form action="?jB=<?php echo $_GET['jB'];?>" method="post" name="EditOrder" runat="server">
    <tr bgcolor="#99CCCC">
      <td bgcolor="#ACB1CC" colspan="9">Consulta de Ordens </td>
    </tr>
    <tr bgcolor="#F2F2F2">
      <td width="5%">N.Ordem</td>
      <td width="12%">Data de EmissÃo </td>
      <td width="12%" bgcolor="#F2F2F2">Emitida por: </td>
      <td width="5%">Estado</td>
      <td width="12%" bgcolor="#F2F2F2">Data da Ordem</td>
      <td width="12%">Atribuido a: </td>
      <td width="12%">Data de Execução </td>
      <td width="12%" bgcolor="#F2F2F2">Executado por:</td>
    </tr>
    <?php
 
	$Search = 'WHERE ';
  	if (isset($_GET['Status']) && $_GET['Status'] != '') {
	$Search .= "Status = '".$_GET['Status']."' AND ";
	}
	$Search .= "a.Status != 5";
   $Results = $GLOBALS['MYD']->db_array("SELECT 
					a.Ref AS Ord,
					main_users.name AS UserCreate,
					DATE(a.Time) AS Time,
					DATE(a.TimeOrder) AS TimeOrder,
					DATE(a.TimeDone) AS TimeDone,
					hcce_status.name AS Status,
					a.sysUserAtribb,
					a.sysUserDone
				FROM ccenter_orders AS a
				INNER JOIN hcce_status ON hcce_status.StatRef = a.Status AND hcce_status.Type = 3
				INNER JOIN main_users ON main_users.ref = a.sysUserCreate
				{$Search}
				ORDER BY a.Ref ASC"); 
	for ($f = 1; $f <= $Results[0]; $f++) { 

		echo '<tr bgcolor="#D3D6E4">
		<td><a href="?jB='.$_GET['jB'].'&Iv='.$Results[$f]['Ord'].'">'.$Results[$f]['Ord'].'</a></td>
		<td>'.$Results[$f]['Time'].'</td>
		<td>'.$Results[$f]['UserCreate'].'</td>
		<td>'.$Results[$f]['Status'].'</td>
		<td>'.$Results[$f]['TimeOrder'].'</td>
		<td>'.$Results[$f]['sysUserAtribb'].'</td>
		<td>'.$Results[$f]['TimeDone'].'</td>
		<td>'.$Results[$f]['sysUserDone'].'</td>
		</tr>';
   } ?>
  </form>
</table>